package com.pmsystem.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.pmsystem.dao.RoomKeyMapper;
import com.pmsystem.pojo.RoomKey;
import com.pmsystem.pojo.RoomKeyExample;
import com.pmsystem.util.BeanUtil;


@Service
public class RoomKeyService {

	@Autowired
	private RoomKeyMapper roomkeyMapper;
	
	/**
	 * 
	 * <p>Title: addRoomkey</p >  
	 * <p>Description: 管理员添加钥匙信息</p >  
	 * @author 泽强
	 * @param roomkey
	 * @return
	 */
	public boolean addRoomkey(RoomKey roomkey) {
		int flag = roomkeyMapper.insertSelective(roomkey);
		return flag==1?true:false;
	}

	/**
	 * 
	 * <p>Title: update</p >  
	 * <p>Description: 管理员修改钥匙信息</p >  
	 * @author 泽强
	 * @param roomkey
	 * @return
	 */
	public boolean update(RoomKey roomkey) {
		int flag = roomkeyMapper.updateByPrimaryKeySelective(roomkey);
		return flag==1?true:false;
	}

	/**
	 * 
	 * <p>Title: CountRoomKey</p >  
	 * <p>Description: 分页查询房间的钥匙数</p >  
	 * @author 泽强
	 * @param map
	 * @return 钥匙数、房间Id、房间名、房间所属用户的id和名字
	 */
	public List<Map<String , Object>> countRoomKey(Map<String, Object> map) {
		Integer pageNo = (Integer) map.get("pageNo");
		Integer pageSize = (Integer) map.get("pageSize");
		if(pageNo!=null&&pageSize!=null) {
			int start = (pageNo - 1) * pageSize;
			map.put("start", start);
		}
		return roomkeyMapper.countRoomKey(BeanUtil.mapToMapWithoutNull(map));
	}

	/**
	 * 
	 * <p>Title: findKey</p >  
	 * <p>Description: 按一定条件查询钥匙</p >  
	 * @author 泽强
	 * @param map
	 * @return
	 */
	public List<RoomKey> findRoomKey(Map<String, Object> map) {
		Integer pageNo = (Integer) map.get("pageNo");
		Integer pageSize = (Integer) map.get("pageSize");
		if(pageNo!=null&&pageSize!=null) {
			int start = (pageNo - 1) * pageSize;
			map.put("start", start);
		} 
		return roomkeyMapper.findRoomKey(BeanUtil.mapToMapWithoutNull(map));
	}
	
	
	/**
	 * 
	 * <p>Title: deleteRoomKeyTableData</p>  
	 * <p>Description:清空房间钥匙数据的表 </p>  
	 * @author 树昌
	 * @return
	 */
	public boolean deleteRoomKeyTableData() {
		
		RoomKeyExample roomKeyExample =new RoomKeyExample();
		int row = roomkeyMapper.deleteByExample(roomKeyExample);
		return row==1?true:false;
	}

	/**
	 * 
	 * <p>Title: findRoomKeyAndRoomName</p >  
	 * <p>Description: 按一定条件查询钥匙 </p >  
	 * @author 泽强
	 * @param map
	 * @return  钥匙信息、房间Id、房间名、房间所属用户的id和名字
	 */
	public List<Map<String , Object>> findRoomKeyAndRoomAndUser(Map<String, Object> map) {
		return roomkeyMapper.findRoomKeyAndRoomAndUser(BeanUtil.mapToMapWithoutNull(map));
	}
	
}
